/*
 * @Author: fengshan0525 2735332396@qq.com
 * @Date: 2023-03-17 20:42:43
 * @LastEditors: fengshan525 2735332396@qq.com
 * @LastEditTime: 2023-10-20 20:43:10
 * @FilePath: \nest-template\src\user\user.controller.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import {
  Controller,
  Post,
  Body,
  Delete,
  Request,
  UseGuards,
  Get,
  Query,
  Req
} from '@nestjs/common';
import { UserService } from './user.service';
import { ApiTags } from '@nestjs/swagger';
import { AdminUsers } from '@libs/db/models/user.model';
import { RoleGuard } from 'src/guards/role.guard';
import { Roles } from 'src/decorations/role.decorator';
// @Controller({
//   path: 'user',
//   version: '1'
// })
@ApiTags('用户')
@Controller('user') // localhost:3000/v1/user, 也可单独控制接口，如下
@UseGuards(RoleGuard)
export class UserController {
  constructor(private readonly userService: UserService) { }

  @Post('create')
  @Roles(['admin'])
  createUser(@Body() body: AdminUsers) {
    return this.userService.createUser(body);
  }

  @Post('update')
  @Roles(['admin'])
  updateUser(@Body() body: AdminUsers) {
    return this.userService.update(body);
  }

  @Post('list')
  queryList(@Body() body) {
    return this.userService.findAll(body);
  }

  @Delete('del')
  @Roles(['admin'])
  deleteUser(@Request() req) {
    return this.userService.remove(req.query.id);
  }

  @Get('userInfo')
  getUserInfo(@Req() req) {
    return this.userService.getUserInfo(req)
  }
}
